﻿using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace DGRobot
{
    public static class Config
    {
        static Config()
        {
            var configPath = new FileInfo("robot.config");
            if (configPath.Exists)
            {
                var config = JObject.Parse(File.ReadAllText(configPath.FullName));
                JToken isDebug;
                if (config.TryGetValue("IsDebug", out isDebug))
                {
                    Config.IsDebug = isDebug.Value<bool>();
                }
                JToken wakeupWord;
                if (config.TryGetValue("WakeupWord", out wakeupWord))
                {
                    Config.WakeupWord = wakeupWord.Value<string>();
                }
                JToken nlpServerUrl;
                if (config.TryGetValue("NlpServerUrl", out nlpServerUrl))
                {
                    Config.NlpServerUrl = nlpServerUrl.Value<string>();
                }
                JToken ttsName;
                if (config.TryGetValue("TTSName", out ttsName))
                {
                    Config.TTSName = ttsName.Value<string>();
                }
                JToken tbmSvrUrl;
                if (config.TryGetValue("TbmServerUrl", out tbmSvrUrl))
                {
                    Config.TbmServerUrl = tbmSvrUrl.Value<string>();
                }
            }
        }
        public static bool IsDebug = true;
        public static string WakeupWord = "盾构|专家|你好";
        public static string NlpServerUrl = "http://127.0.0.1:18081";
        public static string TTSName = "";
        public static string TbmServerUrl = "http://www.ctbmmc.com/";
        public static void Save()
        {
            var configPath = new FileInfo("robot.config");
            File.WriteAllText(configPath.FullName,JsonConvert.SerializeObject(new
            {
                IsDebug,
                WakeupWord,
                NlpServerUrl,
                TTSName,
                TbmServerUrl
            }));
        }
    }
}